The components of the internal table are filled from the file. Only data types with fixed length are allowed. The data must be contained in the file in its full length.
The system reads a binary representation of the internal table from the file. The data is neither converted nor interpreted in this case. Usually, reasonable results are obtained only if the internal table consists of a single column of type ‘X’.
The components of the internal table are filled from the file. If the table contains several columns, the entries in the file must be separated by tabs. No conversion exits are performed.
The following applies for the different data types:
I or N or P or F
The numbers must be formatted according to the decimal representation defined in the user settings.
D
The date must be formatted according to the date format defined in the user settings.
T
The time must be formatted as hh:mm:ss.
内部表格的组成部分由该文件填充。如果表包含多个列,则文件中的条目必须用制表符分隔。不执行转换退出。
以下适用于不同的数据类型:
I或N或P或F
数字必须根据用户设置中定义的十进制表示形式进行格式化。
D
日期必须根据用户设置中定义的日期格式进行格式化。
T
时间的格式必须为hh:mm:ss。
(2)输入参数 CODEPAGE
SAP 输入参数的描述:输出的字符表示。我的理解是上传文件时,对文件中字符处理的编码方式。当输出文件时便是输出文件的字符集。
*--------------------------Variables-----------------------------------* FIELD-SYMBOLS: <FLT_TABLE> TYPE STANDARD TABLE. *----------------------------Logic-------------------------------------* IF GT_TABLE IS INITIAL AND GT_DTEXT IS INITIAL. "展示数据为空 MESSAGE TEXT-E01 TYPE GC_S DISPLAY LIKE GC_E. LEAVE LIST-PROCESSING. ENDIF.
CASE GC_X. WHEN P_DISPL. ASSIGN GT_TABLE TO <FLT_TABLE>. WHEN P_DTEXT. ASSIGN GT_DTEXT TO <FLT_TABLE>. WHEN OTHERS. ENDCASE. CHECK SY-SUBRC EQ 0.
*----------------------------------------------------------------------* * Constants *----------------------------------------------------------------------* CONSTANTS: GC_X TYPE C LENGTH 1 VALUE 'X', GC_S TYPE C LENGTH 1 VALUE 'S', GC_E TYPE C LENGTH 1 VALUE 'E', GC_NULL TYPE C LENGTH 1 VALUE ''.
*----------------------------------------------------------------------* * Variables *----------------------------------------------------------------------* DATA: GV_MESSAGE TYPE C, GV_FILETYPE TYPE C LENGTH 100, GV_SAVEOK TYPE SY-UCOMM, GV_OKCODE TYPE SY-UCOMM.
*----------------------------------------------------------------------* * Structure *----------------------------------------------------------------------* DATA: BEGIN OF GS_TABLE, VALUE TYPE C LENGTH 100, END OF GS_TABLE, BEGIN OF GS_DTEXT, FILED1 TYPE C LENGTH 50, FILED2 TYPE C LENGTH 50, FILED3 TYPE C LENGTH 50, FILED4 TYPE C LENGTH 50, FILED5 TYPE C LENGTH 50, END OF GS_DTEXT, GS_BINTAB TYPE W3MIME.
*----------------------------------------------------------------------* * Internal Table *----------------------------------------------------------------------* DATA: GT_DTEXT LIKE TABLE OF GS_DTEXT, GT_TABLE LIKE TABLE OF GS_TABLE, GT_BINTAB TYPE W3MIMETABTYPE.
*----------------------------------------------------------------------* * Object *----------------------------------------------------------------------* DATA: GO_CONTAINER TYPE REF TO CL_GUI_DOCKING_CONTAINER, GO_HTML_CONTROL TYPE REF TO CL_GUI_HTML_VIEWER.
"Selection Screen SELECTION-SCREEN BEGIN OF BLOCK K01 WITH FRAME TITLE TEXT-T01. PARAMETERS: P_FPATH TYPE RLGRAP-FILENAME. "文件上传路径
SELECTION-SCREEN BEGIN OF LINE. "执行方式 PARAMETERS: P_TEXT NO-DISPLAY. SELECTION-SCREEN COMMENT 1(23) TEXT-T02 FOR FIELD P_TEXT.
"展示数据 ASC SELECTION-SCREEN POSITION 32. PARAMETERS: P_DISPL RADIOBUTTON GROUP GR01 USER-COMMAND UC1 DEFAULT 'X'. SELECTION-SCREEN COMMENT 35(15) TEXT-R01 FOR FIELD P_DISPL.
"展示文件内容(PDF) BIN SELECTION-SCREEN POSITION 50. PARAMETERS: P_DDATA RADIOBUTTON GROUP GR01 . SELECTION-SCREEN COMMENT 52(15) TEXT-R02 FOR FIELD P_DDATA.
"分列Text文件 DAT SELECTION-SCREEN POSITION 75. PARAMETERS: P_DTEXT RADIOBUTTON GROUP GR01 . SELECTION-SCREEN COMMENT 77(15) TEXT-R03 FOR FIELD P_DTEXT. SELECTION-SCREEN END OF LINE.
*&---------------------------------------------------------------------* *& Form SEARCH_HELP_FILEPATH *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& <-- P_FPATH *&---------------------------------------------------------------------* FORM SEARCH_HELP_FILEPATH CHANGING VALUE(PV_FILEPATH) TYPE RLGRAP-FILENAME. CALL FUNCTION 'F4_FILENAME' EXPORTING FIELD_NAME = 'C:\' IMPORTING FILE_NAME = PV_FILEPATH. ENDFORM. *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM GET_DATA . *--------------------------Variables-----------------------------------* DATA: LT_FILE TYPE TABLE OF STRING, LV_INDEX TYPE SY-TABIX, LV_CODEPAGE TYPE ABAP_ENCODING, LV_FILEPATH TYPE STRING, LV_FILETYPE TYPE CHAR10, LV_SPFLIFLAG TYPE C. FIELD-SYMBOLS: <FLT_TABLE> TYPE STANDARD TABLE. *----------------------------Logic-------------------------------------* REFRESH: GT_TABLE,GT_BINTAB,GT_DTEXT.
"获取文件类型 SPLIT P_FPATH AT '.' INTO TABLE LT_FILE. LV_INDEX = LINES( LT_FILE ). READ TABLE LT_FILE INTO GV_FILETYPE INDEX LV_INDEX.
CASE GC_X. WHEN P_DISPL. IF GV_FILETYPE NS 'TXT'. "文件类型不是TXT,无法展示 MESSAGE TEXT-E03 TYPE GC_S DISPLAY LIKE GC_E. LEAVE LIST-PROCESSING. ENDIF. LV_CODEPAGE = '4310'. "UTF-8 LV_FILETYPE = 'ASC'. LV_SPFLIFLAG = GC_NULL. ASSIGN GT_TABLE TO <FLT_TABLE>. CHECK SY-SUBRC EQ 0. WHEN P_DDATA. "校验文件类型 IF GV_FILETYPE NS 'PDF'. "文件类型不是PDF,无法展示 MESSAGE TEXT-E02 TYPE GC_S DISPLAY LIKE GC_E. LEAVE LIST-PROCESSING. ENDIF. LV_FILETYPE = 'BIN'. ASSIGN GT_BINTAB TO <FLT_TABLE>. CHECK SY-SUBRC EQ 0. WHEN P_DTEXT. IF GV_FILETYPE NS 'TXT'. "文件类型不是TXT,无法展示 MESSAGE TEXT-E03 TYPE GC_S DISPLAY LIKE GC_E. LEAVE LIST-PROCESSING. ENDIF. LV_CODEPAGE = '4310'. "UTF-8 LV_FILETYPE = 'DAT'. LV_SPFLIFLAG = GC_X. ASSIGN GT_DTEXT TO <FLT_TABLE>. CHECK SY-SUBRC EQ 0. WHEN OTHERS. ENDCASE.
ENDFORM. *&---------------------------------------------------------------------* *& Form DATA_OPERATION *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM DATA_OPERATION . CASE GC_X. WHEN P_DISPL OR P_DTEXT. PERFORM DISPLAY_DATA. WHEN P_DDATA. IF SY-BATCH IS INITIAL. CALL SCREEN 0100. ENDIF. WHEN OTHERS. ENDCASE. ENDFORM. *&---------------------------------------------------------------------* *& Form DISPLAY_DATA *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM DISPLAY_DATA . *--------------------------Variables-----------------------------------* FIELD-SYMBOLS: <FLT_TABLE> TYPE STANDARD TABLE. *----------------------------Logic-------------------------------------* IF GT_TABLE IS INITIAL AND GT_DTEXT IS INITIAL. "展示数据为空 MESSAGE TEXT-E01 TYPE GC_S DISPLAY LIKE GC_E. LEAVE LIST-PROCESSING. ENDIF.
CASE GC_X. WHEN P_DISPL. ASSIGN GT_TABLE TO <FLT_TABLE>. WHEN P_DTEXT. ASSIGN GT_DTEXT TO <FLT_TABLE>. WHEN OTHERS. ENDCASE. CHECK SY-SUBRC EQ 0.
ENDFORM. *&---------------------------------------------------------------------* *& Form EXIT *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM EXIT . *--------------------------Variables-----------------------------------* CONSTANTS: LC_BACK TYPE SY-UCOMM VALUE 'BACK', LC_EXIT TYPE SY-UCOMM VALUE 'EXIT', LC_CANC TYPE SY-UCOMM VALUE 'CANC'. *----------------------------Logic-------------------------------------* CLEAR: GV_SAVEOK. GV_SAVEOK = GV_OKCODE. CLEAR: GV_OKCODE.
CASE GV_SAVEOK. WHEN LC_BACK OR LC_EXIT OR LC_CANC. LEAVE TO SCREEN 0. WHEN OTHERS. ENDCASE. ENDFORM.